//
//  GeneralSettingViewController.m
//  Weibo
//
//  Created by Anasue on 10/10/15.
//  Copyright © 2015 vvusu. All rights reserved.
//

#import "GeneralSettingViewController.h"
#import "CommonGroup.h"
#import "CommonItem.h"
#import "CommonArrowItem.h"
#import "MBProgressHUD+MJ.h"
#import "CommonSwitchItem.h"
#import "CommonLabelItem.h"
#import "NSString+File.h"
#import "SDImageCache.h"

@interface GeneralSettingViewController ()

@end

@implementation GeneralSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupGroup0];
    [self setupGroup1];

}

- (void)setupGroup0
{
    CommonGroup *group = [CommonGroup group];
    [self.groups addObject:group];
    CommonLabelItem *readMode = [CommonLabelItem itemWithTitle:@"阅读模式"];
    readMode.text = @"有图模式";
    group.items = @[readMode];
    
}

- (void)setupGroup1
{
    CommonGroup *group = [CommonGroup group];
    [self.groups addObject:group];
    CommonArrowItem *clearCache = [CommonArrowItem itemWithTitle:@"清除缓存"];
    
    NSString *imageCachePath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"com.hackmist.SDWebImageCachedefault"];
    long long fileSize = [imageCachePath fileSize];
    clearCache.subTitle = [NSString stringWithFormat:@"%0.1fM",fileSize /(1000.0 * 1000.0)];
    __weak typeof(clearCache) weakClearCache = clearCache;
    __weak typeof(self) weakVc = self;
    clearCache.operation = ^{
        [MBProgressHUD showMessage:@"正在清除缓存..."];
        NSFileManager *mgr = [NSFileManager defaultManager];
        [mgr removeItemAtPath:imageCachePath error:nil];
        weakClearCache.subTitle = nil;
        [weakVc.tableView reloadData];
        [MBProgressHUD hideHUD];
        
    };
    group.items = @[clearCache];
    
}

- (void)dealloc
{

}


@end
